import java.util.Arrays;

public class O57 {
//    public int[] twoSum(int[] nums, int target) {
//        for (int i = 0; i < nums.length; i++) {
//            int t = Arrays.binarySearch(nums,target-nums[i]);
//            if (t>=0&&t!=i)
//                return new int[]{nums[i],nums[t]};
//        }
//        return new int[]{};
//    }
    public static void main(String[] args) {
        O57 o = new O57();
        System.out.println(Arrays.toString(o.twoSum(new int[]{14, 15, 16, 22, 53, 60}, 76)));
    }
    public int[] twoSum(int[] nums, int target) {
        int r = Arrays.binarySearch(nums,target-nums[0]);
        if (r>0)
            return new int[]{nums[0],nums[r]};
        r = -r;
        if (r >= nums.length)
            r = nums.length-1;
        for (int i = 0; i < nums.length; i++) {
            while (nums[i]+nums[r]>=target){
                if (nums[i]+nums[r]==target)
                    return new int[]{nums[i],nums[r]};
                r--;
            }
        }
        return new int[]{nums[0],nums[r]};
    }
}
